<template>
	<view class="k-line-box"> 
		<view class="kline-chart" :style="{height: areaHeight + 'px'}"></view>
		 
	</view>
</template>

<script>
	import helper from '@/common/helper.js'
	import myAjax from '@/common/server.js'
	import WebSocket from '@/common/WebSocket.js' 
	import Stomp from 'stompjs';
	var wv;
	export default {
		data() {
			return { 
			}
		},
		onLoad(option) { 
			let scHeight = uni.getSystemInfoSync().screenHeight;
			let kHeight = 425;
			if(scHeight < 680) {
				this.areaHeight = 425;
			}else{
				this.areaHeight = 460;
				kHeight = 460;
			} 
			this.screenHeight = uni.getSystemInfoSync().screenHeight;
		 
			
			wv = plus.webview.create("","custom-webview",{
					plusrequire:"none",
					'uni-app': 'none',
					top: 85,
					height: kHeight,
					position: 'static',
					scrollIndicator: 'none'
					//scalable: true
			}) 
			wv.loadURL("https://tw.tradingview.com/chart/?symbol=SSE%3A688598")
			 
			var currentWebview = this.$mp.page.$getAppWebview();
			currentWebview.append(wv);  
		},
		computed: {
			cnyPrice: function() {
				const cnyPrice = this.marketLis.cnyPrice || 0;
				const lastTradePrice = this.marketLis.lastTradePrice || 0;
				return helper.accMul(cnyPrice, lastTradePrice)
			},
			totalAmount: function() {
				return helper.getDecimal(this.marketLis.totalAmount, this.marketLis.qtyDecimals)
			}
		},
		onShow() {
			const that = this
			 
		},
		onUnload() {
			const that = this
			 
			that.stompClient.disconnect()
		},
		methods: {
			toDeal() { 
				// uni.setStorageSync('jumpTradeData', "")
				// uni.reLaunch({ url: '../deal-index/deal-index' })
			},
			// 
			getTrade() {
				var that = this;
				myAjax.ajax({
					url: '/transactionPage/app/index',
					data: {
						marketId: that.marketId
					},
					method: 'POST',
					success: (res) => {
						console.log(res.data);
						 
			
					}
				})
			},
			getMarketSocket() {
				var that = this
				var headers = {
					'content-type': 'application/json',
					'lang': 'cn',
					'Access-Control-Allow-Credentials': "false"
				};
				 
				that.stompClient = Stomp.over(new WebSocket(myAjax.soketUrl + '/endpointWisely/websocket', headers));
			 
				const marketIds = that.marketId
			
				that.stompClient.connect(headers, (frame) => { 
					that.stompClient.subscribe(`/topic/tradeListAndMarketOrders/${marketIds}`, (msg) => {
						var data = [] 
						data = JSON.parse(msg.body)
						that.SocketmarketLis = data 
			
					})
				}, (err) => {
				    
				})
			},
		}
	}
</script>

<style lang="less">
	@green: #1CC295;
	@red: #ED2252;  
	@gray: #898C9D;
	
	@white: #FFFFFF;
	@black: #12151E;
	page{
		background-color: @black;
	} 
	
	.kline-chart{
		width: 100%;
		height: 425px;
	}
  
	 
</style>
